﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GalaSoft.MvvmLight.Command;
using HP.Cachalote.WPF.Shared;
using HP.Cachalote.WPF.Model;
using GalaSoft.MvvmLight.Messaging;

namespace HP.Cachalote.WPF.ViewModel
{
    public class TodoItemSearcherViewModel : MyViewModelBase
    {
        public const string StartSearchTodoItemMessageToken = "StartSearchTodoItemMessage";

        /// <summary>
        /// Initializes a new instance of the TodoItemFilterViewModel class.
        /// </summary>
        public TodoItemSearcherViewModel(IDataService dataService)
            : base(dataService) { }

        /// <summary>
        /// The <see cref="SearchKeyWord" /> property's name.
        /// </summary>
        public const string SearchKeyWordPropertyName = "SearchKeyWord";

        private string _searchKeyWord = string.Empty;

        /// <summary>
        /// Sets and gets the SearchKeyWord property.
        /// Changes to that property's value raise the PropertyChanged event. 
        /// </summary>
        public string SearchKeyWord
        {
            get
            {
                return _searchKeyWord;
            }

            set
            {
                if (_searchKeyWord == value)
                {
                    return;
                }

                RaisePropertyChanging(SearchKeyWordPropertyName);
                _searchKeyWord = value;
                RaisePropertyChanged(SearchKeyWordPropertyName);

                // Send StartSearchTodoItemMessage to UnfinishedTodoItemTreeViewModel to 
                // search the matched TodoItems based on provided keyword.
                Messenger.Default.Send<string>(SearchKeyWord, StartSearchTodoItemMessageToken);
            }
        }
    }
}
